<!DOCTYPE html>
<html>
<head>
    <title>Login</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="https://cdn.staticfile.net/twitter-bootstrap/5.1.1/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.staticfile.net/twitter-bootstrap/5.1.1/js/bootstrap.bundle.min.js"></script>
    <script src="https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-M/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://ksylvest.github.io/jquery-growl/javascripts/jquery.growl.js"></script>
    <link href="https://ksylvest.github.io/jquery-growl/stylesheets/jquery.growl.css" rel="stylesheet">
    <style>
        body {
            background: linear-gradient(135deg, #1a1a1a, #0a192f);
            min-height: 100vh;
            display: flex;
            align-items: center;
            font-family: 'Arial', sans-serif;
        }
        .card {
            background: rgba(255, 255, 255, 0.1);
            backdrop-filter: blur(10px);
            border: 1px solid rgba(255, 255, 255, 0.2);
            border-radius: 15px;
            box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
        }
        .card-header {
            background: none;
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        }
        .card-header h3 {
            color: #fff;
            font-weight: 600;
            margin: 10px 0;
        }
        .form-label {
            color: #fff;
        }
        .form-control {
            background: rgba(255, 255, 255, 0.05);
            border: 1px solid rgba(255, 255, 255, 0.1);
            color: #fff;
            transition: all 0.3s ease;
        }
        .form-control:focus {
            background: rgba(255, 255, 255, 0.1);
            border-color: #64ffda;
            box-shadow: 0 0 10px rgba(100, 255, 218, 0.3);
            color: #fff;
        }
        .btn-primary {
            background: linear-gradient(45deg, #64ffda, #0a192f);
            border: none;
            font-weight: 600;
            padding: 12px;
            transition: all 0.3s ease;
        }
        .btn-primary:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(100, 255, 218, 0.4);
            background: linear-gradient(45deg, #0a192f, #64ffda);
        }
        @keyframes float {
            0% { transform: translateY(0px); }
            50% { transform: translateY(-20px); }
            100% { transform: translateY(0px); }
        }
        .card {
            animation: float 6s ease-in-out infinite;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-md-6">
                <div class="card">
                    <div class="card-header">
                        <h3 class="text-center">Welcome Back</h3>
                    </div>
                    <div class="card-body">
                        <form id="loginForm">
                            <div class="mb-4">
                                <label for="username" class="form-label">Username</label>
                                <input type="text" class="form-control" id="username" name="username" required>
                            </div>
                            <div class="mb-4">
                                <label for="password" class="form-label">Password</label>
                                <input type="password" class="form-control" id="password" name="password" required>
                            </div>
                            <button type="submit" class="btn btn-primary w-100">Sign In</button>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script>
        $(document).ready(function() {
            $('#loginForm').on('submit', function(e) {
                e.preventDefault();
                
                $.ajax({
                    url: '/demo/login',
                    type: 'POST',
                    data: {
                        username: $('#username').val(),
                        password: $('#password').val(),
                        csrfmiddlewaretoken: '{{ csrf_token }}'
                    },
                    success: function(response) {
                        if(response.status === 'success') {
                            $.growl.notice({ message: "Login successful!" });
                            window.location.href = '/demo/secret';
                        } else {
                            $.growl.error({ message: response.message });
                        }
                    },
                    error: function() {
                        $.growl.error({ message: "An error occurred. Please try again." });
                    }
                });
            });
        });
    </script>
</body>
</html>